package com.winai.launcher.utils;

import android.widget.Toast;

import com.winai.launcher.Application;

import cn.com.heaton.blelibrary.ble.utils.UuidUtils;

public class Utils {

    private static Toast mToast;

    public static void showToast(String text) {
        if (mToast == null) {
            mToast = Toast.makeText(Application.getInstance(), text, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(text);
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.show();
    }

    public static void showToast( int paramInt) {
        if (mToast == null) {
            mToast = Toast.makeText(Application.getInstance(), paramInt, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(paramInt);
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.show();
    }

    public static String getUuid(String uuid128){
        if (UuidUtils.isBaseUUID(uuid128)){
            return "UUID: 0x"+ UuidUtils.uuid128To16(uuid128, true);
        }
        return uuid128;
    }

    public static int dp2px(float dpValue) {
        final float scale = Application.getInstance().getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
